package de.unidue.langtech.teaching.pp.example;

import java.util.Collection;

import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
import org.apache.uima.fit.component.JCasAnnotator_ImplBase;
import org.apache.uima.fit.util.JCasUtil;
import org.apache.uima.jcas.JCas;

import de.unidue.langtech.teaching.pp.type.BaseTime;
import de.unidue.langtech.teaching.pp.type.TimexEvent;

/**
 * The RuleBasedSolver helps the baseline to match the timex tags to the correct
 * date/duration by setting up rules.
 */

public class RuleBasedSolver extends JCasAnnotator_ImplBase {

	@Override
	public void process(JCas jcas) throws AnalysisEngineProcessException {

		Collection<TimexEvent> timexEvents = JCasUtil.select(jcas,
				TimexEvent.class);
		BaseTime basetime = JCasUtil.selectSingle(jcas, BaseTime.class);

		for (TimexEvent timexEvent : timexEvents) {

			String timexMode = timexEvent.getTimexMode();
			String timeExpression = timexEvent.getTimeExpression().toLowerCase();
			String basetimeValue = basetime.getValue();
			int basetimeYear = basetime.getBasetimeYear();
			int basetimeMonth = basetime.getBasetimeMonth();
			int basetimeDay = basetime.getBasetimeDay();

			// first check the timexmode: date/time or duration/set?

			if ((timexMode.equals("DATE")) || (timexMode.equals("TIME"))) {
				// then check some time expressions like "tomorrow", "today",
				// "yesterday"
				if (timeExpression.contains("tomorrow")
						|| (timeExpression.equals("day"))) {
					basetimeDay = basetimeDay + 1;
					if (basetimeMonth > 9) {
						timexEvent.setDetectedValue(basetimeYear + "-"
								+ basetimeMonth + "-" + basetimeDay);
					} else {
						timexEvent.setDetectedValue(basetimeYear + "-0"
								+ basetimeMonth + "-" + basetimeDay);
					}
				} else if (timeExpression.contains("yesterday")) {
					// if day is between 2 and 10 -> yesterday is between 1 and
					// 9
					if ((basetimeDay > 1) && (basetimeDay < 11)) {
						basetimeDay = basetimeDay - 1;
						if (basetimeMonth > 9) {
							// but goldvalue is between 01 and 09, so don't
							// forget the 0
							timexEvent.setDetectedValue(basetimeYear + "-"
									+ basetimeMonth + "-0" + basetimeDay);
						} else {
							timexEvent.setDetectedValue(basetimeYear + "-0"
									+ basetimeMonth + "-0" + basetimeDay);
						}
					} else if (basetimeDay < 2) {
						// if day is 1, yesterday would be zero. so go back a
						// month and set day to 31
						basetimeDay = basetimeDay + 30;
						basetimeMonth = basetimeMonth - 1;
						if (basetimeMonth > 9) {
							timexEvent.setDetectedValue(basetimeYear + "-"
									+ basetimeMonth + "-" + basetimeDay);
						} else {
							timexEvent.setDetectedValue(basetimeYear + "-0"
									+ basetimeMonth + "-" + basetimeDay);
						}
					} else {
						basetimeDay = basetimeDay - 1;
						if (basetimeMonth > 9) {
							timexEvent.setDetectedValue(basetimeYear + "-"
									+ basetimeMonth + "-" + basetimeDay);
						} else {
							timexEvent.setDetectedValue(basetimeYear + "-0"
									+ basetimeMonth + "-" + basetimeDay);
						}
					}
					// check if time expressions contains seasons or daytimes
				} else if (timeExpression.contains("evening")) {
					timexEvent.setDetectedValue(basetimeValue + "TEV");
				} else if (timeExpression.contains("morning")) {
					timexEvent.setDetectedValue(basetimeValue + "TMO");
				} else if (timeExpression.contains("last spring")) {
					basetimeYear = basetimeYear - 1;
					timexEvent.setDetectedValue(basetimeYear + "-SP");
				} else if (timeExpression.contains("spring")) {
					timexEvent.setDetectedValue(basetimeYear + "-SP");
				} else if (timeExpression.contains("last summer")) {
					basetimeYear = basetimeYear - 1;
					timexEvent.setDetectedValue(basetimeYear + "-SU");
				} else if (timeExpression.contains("summer")) {
					timexEvent.setDetectedValue(basetimeYear + "-SU");
				} else if (timeExpression.contains("last fall") || (timeExpression.contains("last autumn"))) {
					basetimeYear = basetimeYear - 1;
					timexEvent.setDetectedValue(basetimeYear + "-FA");
				} else if (timeExpression.contains("autumn")
						|| (timeExpression.contains("fall"))) {
					timexEvent.setDetectedValue(basetimeYear + "-FA");
				} else if (timeExpression.contains("last winter")) {
					basetimeYear = basetimeYear - 1;
					timexEvent.setDetectedValue(basetimeYear + "-WI");
				} else if (timeExpression.contains("winter")) {
					timexEvent.setDetectedValue(basetimeYear + "-WI");
					// check some time expressions, which refer to present, past
					// or future
				} else if (timeExpression.contains("now")
						|| timeExpression.contains("yet")
						|| timeExpression.contains("current")
						|| timeExpression.contains("moment")) {
					timexEvent.setDetectedValue("PRESENT_REF");
				} else if (timeExpression.contains("recent")
						|| timeExpression.contains("several years ago")
						|| timeExpression.contains("past")) {
					timexEvent.setDetectedValue("PAST_REF");
				} else if (timeExpression.contains("soon")
						|| timeExpression.contains("future")
						|| timeExpression.contains("one day")
						|| timeExpression.contains("later date")) {
					timexEvent.setDetectedValue("FUTURE_REF");
				} else if (timeExpression.contains("next week")) {
					basetimeDay = basetimeDay + 7;
					if (basetimeMonth > 9) {
						if (basetimeDay < 10) {
							timexEvent.setDetectedValue(basetimeYear + "-"
									+ basetimeMonth + "-0" + basetimeDay);
						} else {
							timexEvent.setDetectedValue(basetimeYear + "-"
									+ basetimeMonth + "-" + basetimeDay);
						}
					} else {
						if (basetimeDay < 10) {
							timexEvent.setDetectedValue(basetimeYear + "-0"
									+ basetimeMonth + "-0" + basetimeDay);
						} else {
							timexEvent.setDetectedValue(basetimeYear + "-0"
									+ basetimeMonth + "-" + basetimeDay);
						}
					}
				} else if (timeExpression.contains("last week")) {
					basetimeDay = basetimeDay - 7;
					if (basetimeMonth > 9) {
						if (basetimeDay < 10) {
							timexEvent.setDetectedValue(basetimeYear + "-"
									+ basetimeMonth + "-0" + basetimeDay);
						} else {
							timexEvent.setDetectedValue(basetimeYear + "-"
									+ basetimeMonth + "-" + basetimeDay);
						}
					} else {
						if (basetimeDay < 10) {
							timexEvent.setDetectedValue(basetimeYear + "-0"
									+ basetimeMonth + "-0" + basetimeDay);
						} else {
							timexEvent.setDetectedValue(basetimeYear + "-0"
									+ basetimeMonth + "-" + basetimeDay);
						}
					}
				} else if (timeExpression.contains("this month")) {
					if (basetimeMonth > 9) {
						timexEvent.setDetectedValue(basetimeYear + "-"
								+ basetimeMonth);
					} else {
						timexEvent.setDetectedValue(basetimeYear + "-0"
								+ basetimeMonth);
					}
				} else if (timeExpression.contains("next month")) {
					if (basetimeMonth > 11) {
						basetimeMonth = 1;
						basetimeYear = basetimeYear + 1;
					} else {
						basetimeMonth = basetimeMonth + 1;
					}
					if (basetimeMonth > 9) {
						timexEvent.setDetectedValue(basetimeYear + "-"
								+ basetimeMonth);
					} else {
						timexEvent.setDetectedValue(basetimeYear + "-0"
								+ basetimeMonth);
					}
				} else if (timeExpression.contains("last month")) {
					if (basetimeMonth > 1) {
						basetimeMonth = basetimeMonth - 1;
					} else {
						basetimeYear = basetimeYear - 1;
						basetimeMonth = 12;
					}
					if (basetimeMonth > 9) {
						timexEvent.setDetectedValue(basetimeYear + "-"
								+ basetimeMonth);
					} else {
						timexEvent.setDetectedValue(basetimeYear + "-0"
								+ basetimeMonth);
					}

				} else if (timeExpression.contains("next year")) {
					basetimeYear = basetimeYear + 1;
					timexEvent.setDetectedValue(basetimeYear + "");
				} else if (timeExpression.contains("year")
						&& (timeExpression.contains("end"))) {
					timexEvent.setDetectedValue(basetimeYear + "");
				} else if (timeExpression.contains("last year") || (timeExpression.contains("year ago"))) {
					basetimeYear = basetimeYear - 1;
					timexEvent.setDetectedValue(basetimeYear + "");
				} else if (timeExpression.contains("two years ago")) {
					basetimeYear = basetimeYear - 2;
					timexEvent.setDetectedValue(basetimeYear + "");
				} else if (timeExpression.contains("three years ago")) {
					basetimeYear = basetimeYear - 3;
					timexEvent.setDetectedValue(basetimeYear + "");
				} else if (timeExpression.contains("four years ago")) {
					basetimeYear = basetimeYear - 4;
					timexEvent.setDetectedValue(basetimeYear + "");
				} else if (timeExpression.contains("five years ago")) {
					basetimeYear = basetimeYear - 5;
					timexEvent.setDetectedValue(basetimeYear + "");
				} else if (timeExpression.contains("first")
						&& timeExpression.contains("quarter")) {
					timexEvent.setDetectedValue(basetimeYear + "-Q1");
				} else if (timeExpression.contains("second")
						&& timeExpression.contains("quarter")) {
					timexEvent.setDetectedValue(basetimeYear + "-Q2");
				} else if (timeExpression.contains("third")
						&& timeExpression.contains("quarter")) {
					timexEvent.setDetectedValue(basetimeYear + "-Q3");
				} else if (timeExpression.contains("fourth")
						&& timeExpression.contains("quarter")) {
					timexEvent.setDetectedValue(basetimeYear + "-Q4");
				} else if (timeExpression.equals("january")) {
					timexEvent.setDetectedValue(basetimeYear + "-01");
				} else if (timeExpression.equals("february")) {
					timexEvent.setDetectedValue(basetimeYear + "-02");
				} else if (timeExpression.equals("march")) {
					timexEvent.setDetectedValue(basetimeYear + "-03");
				} else if (timeExpression.equals("april")) {
					timexEvent.setDetectedValue(basetimeYear + "-04");
				} else if (timeExpression.equals("may")) {
					timexEvent.setDetectedValue(basetimeYear + "-05");
				} else if (timeExpression.equals("june")) {
					timexEvent.setDetectedValue(basetimeYear + "-06");
				} else if (timeExpression.equals("july")) {
					timexEvent.setDetectedValue(basetimeYear + "-07");
				} else if (timeExpression.equals("august")) {
					timexEvent.setDetectedValue(basetimeYear + "-08");
				} else if (timeExpression.equals("september")) {
					timexEvent.setDetectedValue(basetimeYear + "-09");
				} else if (timeExpression.equals("october")) {
					timexEvent.setDetectedValue(basetimeYear + "-10");
				} else if (timeExpression.equals("november")) {
					timexEvent.setDetectedValue(basetimeYear + "-11");
				} else if (timeExpression.equals("december")) {
					timexEvent.setDetectedValue(basetimeYear + "-12");
				} else if (timeExpression.contains("1959")) {
					timexEvent.setDetectedValue("1959");
				} else if (timeExpression.contains("1960")) {
					timexEvent.setDetectedValue("1960");
				} else if (timeExpression.contains("1961")) {
					timexEvent.setDetectedValue("1961");
				} else if (timeExpression.contains("1962")) {
					timexEvent.setDetectedValue("1962");
				} else if (timeExpression.contains("1963")) {
					timexEvent.setDetectedValue("1963");
				} else if (timeExpression.contains("1964")) {
					timexEvent.setDetectedValue("1964");
				} else if (timeExpression.contains("1965")) {
					timexEvent.setDetectedValue("1965");
				} else if (timeExpression.contains("1966")) {
					timexEvent.setDetectedValue("1966");
				} else if (timeExpression.contains("1967")) {
					timexEvent.setDetectedValue("1967");
				} else if (timeExpression.contains("1968")) {
					timexEvent.setDetectedValue("1968");
				} else if (timeExpression.contains("1969")) {
					timexEvent.setDetectedValue("1969");
				} else if (timeExpression.contains("1970")) {
					timexEvent.setDetectedValue("1970");
				} else if (timeExpression.contains("1971")) {
					timexEvent.setDetectedValue("1971");
				} else if (timeExpression.contains("1972")) {
					timexEvent.setDetectedValue("1972");
				} else if (timeExpression.contains("1973")) {
					timexEvent.setDetectedValue("1973");
				} else if (timeExpression.contains("1974")) {
					timexEvent.setDetectedValue("1974");
				} else if (timeExpression.contains("1975")) {
					timexEvent.setDetectedValue("1975");
				} else if (timeExpression.contains("1976")) {
					timexEvent.setDetectedValue("1976");
				} else if (timeExpression.contains("1977")) {
					timexEvent.setDetectedValue("1977");
				} else if (timeExpression.contains("1978")) {
					timexEvent.setDetectedValue("1978");
				} else if (timeExpression.contains("1979")) {
					timexEvent.setDetectedValue("1979");
				} else if (timeExpression.contains("1980")) {
					timexEvent.setDetectedValue("1980");
				} else if (timeExpression.contains("1981")) {
					timexEvent.setDetectedValue("1981");
				} else if (timeExpression.contains("1982")) {
					timexEvent.setDetectedValue("1982");
				} else if (timeExpression.contains("1983")) {
					timexEvent.setDetectedValue("1983");
				} else if (timeExpression.contains("1984")) {
					timexEvent.setDetectedValue("1984");
				} else if (timeExpression.contains("1985")) {
					timexEvent.setDetectedValue("1985");
				} else if (timeExpression.contains("1986")) {
					timexEvent.setDetectedValue("1986");
				} else if (timeExpression.contains("1987")) {
					timexEvent.setDetectedValue("1987");
				} else if (timeExpression.contains("1988")) {
					timexEvent.setDetectedValue("1988");
				} else if (timeExpression.contains("1989")) {
					timexEvent.setDetectedValue("1989");
				} else if (timeExpression.contains("1990")) {
					timexEvent.setDetectedValue("1990");
				} else if (timeExpression.contains("1991")) {
					timexEvent.setDetectedValue("1991");
				} else if (timeExpression.contains("1992")) {
					timexEvent.setDetectedValue("1992");
				} else if (timeExpression.contains("1993")) {
					timexEvent.setDetectedValue("1993");
				} else if (timeExpression.contains("1994")) {
					timexEvent.setDetectedValue("1994");
				} else if (timeExpression.contains("1995")) {
					timexEvent.setDetectedValue("1995");
				} else if (timeExpression.contains("1996")) {
					timexEvent.setDetectedValue("1996");
				} else if (timeExpression.contains("1997")) {
					timexEvent.setDetectedValue("1997");
				} else if (timeExpression.contains("1998")) {
					timexEvent.setDetectedValue("1998");
				} else if (timeExpression.contains("1999")) {
					timexEvent.setDetectedValue("1999");
				} else if (timeExpression.contains("2000")) {
					timexEvent.setDetectedValue("2000");
				} else {
					// default value for all dates and times, if no rule
					// matches: the basetime of the document
					// but: some basetimes are like "YYYY-MM-DDtime", so we only
					// want
					// the first 10 characters to be set as detectedValue
					timexEvent.setDetectedValue(basetimeValue.substring(0, 10));
				}
				// now check for durations
			} else if (timexMode.equals("DURATION")
					|| (timexMode.equals("SET"))) {
				if (timeExpression.contains("annually")) {
					timexEvent.setDetectedValue("XXXX");
				} else if (timeExpression.contains("quarter")) {
					if (timeExpression.contains("first")) {
						timexEvent.setDetectedValue("XXXX-Q1");
					} else if (timeExpression.contains("second")) {
						timexEvent.setDetectedValue("XXXX-Q2");
					} else if (timeExpression.contains("third")) {
						timexEvent.setDetectedValue("XXXX-Q3");
					} else if (timeExpression.contains("fourth")) {
						timexEvent.setDetectedValue("XXXX-Q4");
					} else {
						timexEvent.setDetectedValue("XXXX-QX");
					}
				} else if (timeExpression.contains("weekend")) {
					timexEvent.setDetectedValue("P2D");
				} else if (timeExpression.contains("day")) {
					if (timeExpression.equals("day")
							|| (timeExpression.equals("daily"))
							|| (timeExpression.contains("every"))) {
						timexEvent.setDetectedValue("P1D");
					} else if (timeExpression.contains("one")
							|| (timeExpression.contains("1"))) {
						timexEvent.setDetectedValue("P1D");
					} else if (timeExpression.contains("two")
							|| (timeExpression.contains("2"))) {
						timexEvent.setDetectedValue("P2D");
					} else if (timeExpression.contains("three")
							|| (timeExpression.contains("3"))) {
						timexEvent.setDetectedValue("P3D");
					} else if (timeExpression.contains("four")
							|| (timeExpression.contains("4"))) {
						timexEvent.setDetectedValue("P4D");
					} else if (timeExpression.contains("five")
							|| (timeExpression.contains("5"))) {
						timexEvent.setDetectedValue("P5D");
						// check "sixty" before "six", otherwise it will get it
						// as "six", even if it's "sixty"
					} else if (timeExpression.contains("sixty")
							|| (timeExpression.contains("60"))) {
						timexEvent.setDetectedValue("P60D");
					} else if (timeExpression.contains("six")
							|| (timeExpression.contains("6"))) {
						timexEvent.setDetectedValue("P6D");
					} else if (timeExpression.contains("seventy")
							|| (timeExpression.contains("70"))) {
						timexEvent.setDetectedValue("P70D");
					} else if (timeExpression.contains("seven")
							|| (timeExpression.contains("7"))) {
						timexEvent.setDetectedValue("P7D");
					} else if (timeExpression.contains("eighty")
							|| (timeExpression.contains("80"))) {
						timexEvent.setDetectedValue("P80D");
					} else if (timeExpression.contains("eight")
							|| (timeExpression.contains("8"))) {
						timexEvent.setDetectedValue("P8D");
					} else if (timeExpression.contains("ninety")
							|| (timeExpression.contains("90"))) {
						timexEvent.setDetectedValue("P90D");
					} else if (timeExpression.contains("nine")
							|| (timeExpression.contains("9"))) {
						timexEvent.setDetectedValue("P9D");
					} else if (timeExpression.contains("ten")
							|| (timeExpression.contains("10"))) {
						timexEvent.setDetectedValue("P10D");
					} else if (timeExpression.contains("forteen")
							|| (timeExpression.contains("14"))) {
						timexEvent.setDetectedValue("P14D");
					} else if (timeExpression.contains("twenty")
							|| (timeExpression.contains("20"))) {
						timexEvent.setDetectedValue("P20D");
					} else if (timeExpression.contains("thirty")
							|| (timeExpression.contains("30"))) {
						timexEvent.setDetectedValue("P30D");
					} else if (timeExpression.contains("forty")
							|| (timeExpression.contains("40"))) {
						timexEvent.setDetectedValue("P40D");
					} else if (timeExpression.contains("fifty")
							|| (timeExpression.contains("50"))) {
						timexEvent.setDetectedValue("P50D");
					} else if (timeExpression.contains("hundred")
							|| (timeExpression.contains("100"))) {
						timexEvent.setDetectedValue("P100D");
					} else {
						// default day value
						timexEvent.setDetectedValue("PXD");
					}
				} else if (timeExpression.contains("week")) {
					if (timeExpression.contains("one")
							|| (timeExpression.equals("week"))) {
						timexEvent.setDetectedValue("P1W");
					} else if (timeExpression.contains("next")) {
						basetimeDay = basetimeDay + 7;
						if (basetimeMonth > 9) {
							if (basetimeDay < 10) {
								timexEvent.setDetectedValue(basetimeYear + "-"
										+ basetimeMonth + "-0" + basetimeDay);
							} else {
								timexEvent.setDetectedValue(basetimeYear + "-"
										+ basetimeMonth + "-" + basetimeDay);
							}
						} else {
							if (basetimeDay < 10) {
								timexEvent.setDetectedValue(basetimeYear + "-0"
										+ basetimeMonth + "-0" + basetimeDay);
							} else {
								timexEvent.setDetectedValue(basetimeYear + "-0"
										+ basetimeMonth + "-" + basetimeDay);
							}
						}
					} else if (timeExpression.contains("last")) {
						basetimeDay = basetimeDay - 7;
						if (basetimeMonth > 9) {
							if (basetimeDay < 10) {
								timexEvent.setDetectedValue(basetimeYear + "-"
										+ basetimeMonth + "-0" + basetimeDay);
							} else {
								timexEvent.setDetectedValue(basetimeYear + "-"
										+ basetimeMonth + "-" + basetimeDay);
							}
						} else {
							if (basetimeDay < 10) {
								timexEvent.setDetectedValue(basetimeYear + "-0"
										+ basetimeMonth + "-0" + basetimeDay);
							} else {
								timexEvent.setDetectedValue(basetimeYear + "-0"
										+ basetimeMonth + "-" + basetimeDay);
							}
						}
					} else if (timeExpression.contains("two")) {
						timexEvent.setDetectedValue("P2W");
					} else if (timeExpression.contains("three")) {
						timexEvent.setDetectedValue("P3W");
					} else if (timeExpression.contains("four")) {
						timexEvent.setDetectedValue("P4W");
					} else if (timeExpression.contains("five")) {
						timexEvent.setDetectedValue("P5W");
					} else if (timeExpression.contains("six")) {
						timexEvent.setDetectedValue("P6W");
					} else if (timeExpression.contains("seven")) {
						timexEvent.setDetectedValue("P7W");
					} else if (timeExpression.contains("eight")) {
						timexEvent.setDetectedValue("P8W");
					} else if (timeExpression.contains("nine")) {
						timexEvent.setDetectedValue("P9W");
					} else if (timeExpression.contains("ten")) {
						timexEvent.setDetectedValue("P10W");
					} else {
						timexEvent.setDetectedValue("PXW");
					}
				} else if (timeExpression.contains("decade")) {
					timexEvent.setDetectedValue("P10Y");
				} else if (timeExpression.contains("century")) {
					timexEvent.setDetectedValue("P100Y");
				} else if (timeExpression.contains("month")) {
					if (timeExpression.contains("one")
							|| (timeExpression.contains("this"))
							|| (timeExpression.equals("month"))
							|| (timeExpression.equals("a month"))) {
						timexEvent.setDetectedValue("P1M");
					} else if (timeExpression.contains("twelve")
							|| (timeExpression.contains("12"))) {
						timexEvent.setDetectedValue("P12M");
					} else if (timeExpression.contains("twenty")
							|| (timeExpression.contains("20"))) {
						timexEvent.setDetectedValue("P20M");
					} else if (timeExpression.contains("two")
							|| (timeExpression.contains("2"))) {
						timexEvent.setDetectedValue("P2M");
					} else if (timeExpression.contains("three")
							|| (timeExpression.contains("3"))) {
						timexEvent.setDetectedValue("P3M");
					} else if (timeExpression.contains("four")
							|| (timeExpression.contains("4"))) {
						timexEvent.setDetectedValue("P4M");
					} else if (timeExpression.contains("five")
							|| (timeExpression.contains("5"))) {
						timexEvent.setDetectedValue("P5M");
					} else if (timeExpression.contains("six")
							|| (timeExpression.contains("6"))) {
						timexEvent.setDetectedValue("P6M");
					} else if (timeExpression.contains("seven")
							|| (timeExpression.contains("7"))) {
						timexEvent.setDetectedValue("P7M");
					} else if (timeExpression.contains("eighteen")
							|| (timeExpression.contains("18"))) {
						timexEvent.setDetectedValue("P18M");
					} else if (timeExpression.contains("eight")
							|| (timeExpression.contains("8"))) {
						timexEvent.setDetectedValue("P8M");
					} else if (timeExpression.contains("nine")
							|| (timeExpression.contains("9"))) {
						timexEvent.setDetectedValue("P9M");
					} else if (timeExpression.contains("ten")
							|| (timeExpression.contains("10"))) {
						timexEvent.setDetectedValue("P10M");
					} else if (timeExpression.contains("eleven")
							|| (timeExpression.contains("11"))) {
						timexEvent.setDetectedValue("P11M");
					} else {
						timexEvent.setDetectedValue("PXM");
					}
				} else if (timeExpression.contains("year")) {
					if (timeExpression.equals("year")
							|| (timeExpression.contains("every"))) {
						timexEvent.setDetectedValue("P1Y");
					} else if (timeExpression.equals("years")) {
						timexEvent.setDetectedValue("PXY");
					} else if (timeExpression.contains("ten")
							|| (timeExpression.contains("10"))) {
						timexEvent.setDetectedValue("P10Y");
					} else if (timeExpression.contains("twenty")
							|| (timeExpression.contains("20"))) {
						timexEvent.setDetectedValue("P20Y");
					} else if (timeExpression.contains("thirty")
							|| (timeExpression.contains("30"))) {
						timexEvent.setDetectedValue("P30Y");
					} else if (timeExpression.contains("forty")
							|| (timeExpression.contains("40"))) {
						timexEvent.setDetectedValue("P40Y");
					} else if (timeExpression.contains("fifty")
							|| (timeExpression.contains("50"))) {
						timexEvent.setDetectedValue("P50Y");
					} else if (timeExpression.contains("hundred")
							|| (timeExpression.contains("100"))) {
						timexEvent.setDetectedValue("P100Y");
					} else if (timeExpression.contains("one")
							|| (timeExpression.contains("1"))) {
						timexEvent.setDetectedValue("P1Y");
					} else if (timeExpression.contains("two")
							|| (timeExpression.contains("2"))
							|| (timeExpression.contains("couple"))) {
						timexEvent.setDetectedValue("P2Y");
					} else if (timeExpression.contains("three")
							|| (timeExpression.contains("3"))) {
						timexEvent.setDetectedValue("P3Y");
					} else if (timeExpression.contains("four")
							|| (timeExpression.contains("4"))) {
						timexEvent.setDetectedValue("P4Y");
					} else if (timeExpression.contains("five")
							|| (timeExpression.contains("5"))) {
						timexEvent.setDetectedValue("P5Y");
					} else if (timeExpression.contains("sixty")
							|| (timeExpression.contains("60"))) {
						timexEvent.setDetectedValue("P60Y");
					} else if (timeExpression.contains("six")
							|| (timeExpression.contains("6"))) {
						timexEvent.setDetectedValue("P6Y");
					} else if (timeExpression.contains("seventy")
							|| (timeExpression.contains("70"))) {
						timexEvent.setDetectedValue("P70Y");
					} else if (timeExpression.contains("seven")
							|| (timeExpression.contains("7"))) {
						timexEvent.setDetectedValue("P7Y");
					} else if (timeExpression.contains("eighty")
							|| (timeExpression.contains("80"))) {
						timexEvent.setDetectedValue("P80Y");
					} else if (timeExpression.contains("eight")
							|| (timeExpression.contains("8"))) {
						timexEvent.setDetectedValue("P8Y");
					} else if (timeExpression.contains("ninety")
							|| (timeExpression.contains("90"))) {
						timexEvent.setDetectedValue("P90Y");
					} else if (timeExpression.contains("nine")
							|| (timeExpression.contains("9"))) {
						timexEvent.setDetectedValue("P9Y");
					} else {
						timexEvent.setDetectedValue("PXY");
					}
				} else {
					// default value for all durations and sets, if no rule
					// matches: 1 year
					timexEvent.setDetectedValue("XXXX");
				}
			} else {
				System.out.println("Timex tag does not match.");
			}
		}
	}

}
